﻿using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Linq;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    public partial class ITXEXRPT
    {
        public void TSTEK02(DataSet db)
        {
            int x = 4, y = 0;
            string EKPPOSTYP = "";
            DataTable dtOutput = new DataTable();
            try
            {

                #region======Title===========
                //这里设置抬头和输出的列
                exAgent.SetCellValue(x, y + 1, "状态"); dtOutput.Columns.Add("EKPSA", typeof(System.String));
                exAgent.SetCellValue(x, y + 2, "类型"); dtOutput.Columns.Add("TYP", typeof(System.String));
                exAgent.SetCellValue(x, y + 3, ""); dtOutput.Columns.Add("EKKAUFKRS", typeof(System.String));
                exAgent.SetCellValue(x, y + 4, "采购单"); dtOutput.Columns.Add("EKKAUFLFD", typeof(System.String));
                exAgent.SetCellValue(x, y + 5, ""); dtOutput.Columns.Add("EKPAUFPOS", typeof(System.String));
                exAgent.SetCellValue(x, y + 6, "供应商"); dtOutput.Columns.Add("EKKLIEFNR", typeof(System.String));
                exAgent.SetCellValue(x, y + 7, "供应商名称"); dtOutput.Columns.Add("LSLIEFNA", typeof(System.String));
                exAgent.SetCellValue(x, y + 8, "销售单"); dtOutput.Columns.Add("ABAVKAUF", typeof(System.String));
                exAgent.SetCellValue(x, y + 9, "客户"); dtOutput.Columns.Add("CUSTOMER", typeof(System.String));
                exAgent.SetCellValue(x, y + 10, "系列"); dtOutput.Columns.Add("KOLL", typeof(System.String));
                exAgent.SetCellValue(x, y + 11, "品种编号"); dtOutput.Columns.Add("PART", typeof(System.String));
                exAgent.SetCellValue(x, y + 12, "色号"); dtOutput.Columns.Add("PFARBE", typeof(System.String));
                exAgent.SetCellValue(x, y + 13, "数量"); dtOutput.Columns.Add("EKPME1", typeof(System.String));
                exAgent.SetCellValue(x, y + 14, "实收"); dtOutput.Columns.Add("EKPME3", typeof(System.String));
                exAgent.SetCellValue(x, y + 15, "交期"); dtOutput.Columns.Add("EKPLTERM", typeof(System.String));
                exAgent.SetCellValue(x, y + 16, "船样"); dtOutput.Columns.Add("EKPGENDAT1", typeof(System.String));
                exAgent.SetCellValue(x, y + 17, "单价"); dtOutput.Columns.Add("EKPPRME", typeof(System.String));
                exAgent.SetCellValue(x, y + 18, "币种"); dtOutput.Columns.Add("EKKWAEHRSL", typeof(System.String));
                exAgent.SetCellValue(x, y + 19, "总金额"); dtOutput.Columns.Add("VALUE", typeof(System.String));
                exAgent.SetCellValue(x, y + 20, "附加费"); dtOutput.Columns.Add("SUR", typeof(System.String));
                exAgent.SetCellValue(x, y + 21, "折扣"); dtOutput.Columns.Add("DIS", typeof(System.String));
                exAgent.SetCellValue(x, y + 22, "付款方式"); dtOutput.Columns.Add("ZAHLBED", typeof(System.String));
                exAgent.SetCellValue(x, y + 23, "贸易方式"); dtOutput.Columns.Add("LIEFBED", typeof(System.String));
                exAgent.SetCellValue(x, y + 24, "运输方式"); dtOutput.Columns.Add("SART", typeof(System.String));
                exAgent.SetCellValue(x, y + 25, "承运人"); dtOutput.Columns.Add("VSPED", typeof(System.String));
                exAgent.SetCellValue(x, y + 26, "确认"); dtOutput.Columns.Add("VAAFILLER", typeof(System.String));
                exAgent.SetCellValue(x, y + 27, "负责人"); dtOutput.Columns.Add("EKPSACHB", typeof(System.String));
                //exAgent.SetCellValue(3, y + 32, "合同号"); dtOutput.Columns.Add("VKKBESTNR", typeof(System.String));
                //exAgent.SetCellValue(3, y + 33, "产品组"); dtOutput.Columns.Add("VAAPRGR", typeof(System.String));
                //exAgent.SetCellValue(3, y + 34, "产品组"); dtOutput.Columns.Add("VAAARTGRP", typeof(System.String));
                //exAgent.SetCellValue(3, y + 35, "创建日期"); dtOutput.Columns.Add("VKPNEUDAT", typeof(System.String));
                //exAgent.SetCellValue(3, y + 36, "跟单"); dtOutput.Columns.Add("VKPNEUBEN", typeof(System.String));
                //exAgent.SetCellValue(3, y + 37, "负责人"); dtOutput.Columns.Add("VKPSACHBE", typeof(System.String));
                #endregion


                #region======ConvertData===
                #endregion
                //var qGW = from GW in db.Tables["EKPOS"].AsEnumerable()
                //          group GW by new
                //          {
                //              PT = GW["EKPPOSTYP"].ToString(),
                //          }
                //              into g
                //              select new
                //              {
                //                  KEY = g.Key,
                //              };
                ////上面是若需要对列表分组输出，现在本身屏蔽了。
                //foreach (var GW in qGW)
                //{
                //    EKPPOSTYP = GW.KEY.PT;
                //    exAgent.RenameSheet(date);
                DataRow[] rows = db.Tables["EKPOS"].Select("EKPSA='PO'");
                DataTable dtSoruce = rows.CopyToDataTable();
                dtOutput.Clear();
                dtOutput.Merge(dtSoruce, false, MissingSchemaAction.Ignore);
                foreach (DataRow rx in dtOutput.Rows)
                {//这里处理需要进行的数字和中文
                    rx["TYP"] = Helper.GetGB2312Value(rx["TYP"].ToString());
                    rx["CUSTOMER"] = Helper.GetGB2312Value(rx["CUSTOMER"].ToString());
                    //rx["SUPPLIER"] = Helper.GetGB2312Value(rx["SUPPLIER"].ToString());
                    //rx["POORDER"] = Helper.GetGB2312Value(rx["POORDER"].ToString());
                    rx["EKPME1"] = (Convert.ToInt32(rx["EKPME1"]) * 0.01).ToString().Trim();
                    rx["EKPME3"] = (Convert.ToInt32(rx["EKPME3"]) * 0.01).ToString().Trim();
                    rx["EKPPRME"] = (Convert.ToInt32(rx["EKPPRME"]) * 0.001).ToString().Trim();
                    //rx["VKPFREIGE"] = (Convert.ToInt32(rx["VKPFREIGE"]) * 0.01).ToString().Trim();
                    //rx["VKPVERS"] = (Convert.ToInt32(rx["VKPVERS"]) * 0.01).ToString().Trim();
                    //rx["VKPFAKT"] = (Convert.ToInt32(rx["VKPFAKT"]) * 0.01).ToString().Trim();
                    //rx["VKPPREIS"] = (Convert.ToInt32(rx["VKPPREIS"]) * 0.001).ToString().Trim();
                }
                #region====Excel==========
                int count = dtOutput.Rows.Count;
                //exAgent.RangeCopy(4, 50, 5, 4 + count);
                exAgent.DataTableToExcel(dtOutput, x, 1);

                //MergeSame(x, count);
                exAgent.SetCellValue(1, 1, 1);
                exAgent.BatchConvert2Number(4, 13, count + 3, 17);
                exAgent.BatchConvert2Number(4, 19, count + 3, 21);
                //exAgent.BatchConvert2Number(4, 16, count + 3, 16);
                exAgent.SetCellValue(1, 1, "采购统计 ");
                #endregion

            }
            //}
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            finally
            {
                EventDispatcher.Instance.RaiseStatus("完成", StatusEventType.StopProgress);
            }
        }
         
        private void TSTEK02x(DataSet db)  
        {
            try
            {
                DataTable tbEKKOPF = dsSource.Tables["EKPOS"];                
                for (int i = 0; i < tbEKKOPF.Rows.Count; i++)
                {
                    DataRow TEMP=tbEKKOPF.Rows[i];
                    string EKPSA = "";
                    EKPSA = TEMP["EKPSA"].ToString().Trim(); exAgent.SetCellValue(i + 3, 1, EKPSA);
                    string TYP = "";//中文
                    TYP = TEMP["TYP"].ToString().Trim(); exAgent.SetCellValue(i + 3, 2, Helper.GetGB2312Value(TYP).ToString().Trim());
                    string EKKAUFKRS = "";
                    EKKAUFKRS = TEMP["EKKAUFKRS"].ToString().Trim(); exAgent.SetCellValue(i + 3, 3, EKKAUFKRS);
                    string EKKAUFLFD = "";
                    EKKAUFLFD = TEMP["EKKAUFLFD"].ToString().Trim(); exAgent.SetCellValue(i + 3, 4, EKKAUFLFD);
                    string EKPAUFPOS = "";
                    EKPAUFPOS = TEMP["EKPAUFPOS"].ToString().Trim(); exAgent.SetCellValue(i + 3, 5, EKPAUFPOS);
                    string EKKLIEFNR = "";//pumn
                    EKKLIEFNR = TEMP["EKKLIEFNR"].ToString().Trim(); exAgent.SetCellValue(i + 3, 6, EKKLIEFNR);
                    string LSLIEFNA = "";//中文
                    LSLIEFNA = TEMP["LSLIEFNA"].ToString().Trim(); exAgent.SetCellValue(i + 3, 7, LSLIEFNA);
                    string ABAVKAUF = "";
                    ABAVKAUF = TEMP["ABAVKAUF"].ToString().Trim(); exAgent.SetCellValue(i + 3, 8, ABAVKAUF);
                    string CUSTOMER = "";//中文
                    CUSTOMER = TEMP["CUSTOMER"].ToString().Trim(); exAgent.SetCellValue(i + 3, 9, Helper.GetGB2312Value(CUSTOMER).ToString().Trim());
                    string KOLL = "";
                    KOLL = TEMP["KOLL"].ToString().Trim(); exAgent.SetCellValue(i + 3, 10, KOLL);
                    string PART = "";
                    PART = TEMP["PART"].ToString().Trim(); exAgent.SetCellValue(i + 3, 11, PART);
                    string PFARBE = "";
                    PFARBE = TEMP["PFARBE"].ToString().Trim(); exAgent.SetCellValue(i + 3, 12, PFARBE);
                    string EKPME1 = "";//D100
                    EKPME1 =(Convert.ToInt32(TEMP["EKPME1"])*0.01).ToString().Trim(); exAgent.SetCellValue(i + 3, 13, EKPME1);
                    string EKPME3 = "";//D100
                    EKPME3 =(Convert.ToInt32(TEMP["EKPME3"])*0.01).ToString().Trim(); exAgent.SetCellValue(i + 3, 14, EKPME3);
                    string EKPLTERM = "";
                    EKPLTERM = TEMP["EKPLTERM"].ToString().Trim(); exAgent.SetCellValue(i + 3, 15, EKPLTERM);
                    string EKPGENDAT1 = "";
                    EKPGENDAT1 = TEMP["EKPGENDAT1"].ToString().Trim(); exAgent.SetCellValue(i + 3, 16, EKPGENDAT1);
                    string EKPPRME = "";//price
                    EKPPRME = (Convert.ToInt32(TEMP["EKPPRME"])*0.001).ToString().Trim(); exAgent.SetCellValue(i + 3, 17, EKPPRME);
                    string EKKWAEHRSL = "";
                    EKKWAEHRSL = TEMP["EKKWAEHRSL"].ToString().Trim(); exAgent.SetCellValue(i + 3, 18, EKKWAEHRSL);
                    string VALUE = "";
                    VALUE = TEMP["VALUE"].ToString().Trim(); exAgent.SetCellValue(i + 3, 19, VALUE);
                    string SUR = "";
                    SUR = TEMP["SUR"].ToString().Trim(); exAgent.SetCellValue(i + 3, 20, SUR);
                    string DIS = "";
                    DIS = TEMP["DIS"].ToString().Trim(); exAgent.SetCellValue(i + 3, 21, DIS);
                    string ZAHLBED = "";
                    ZAHLBED = TEMP["ZAHLBED"].ToString().Trim(); exAgent.SetCellValue(i + 3, 22, ZAHLBED);
                    string LIEFBED = "";
                    LIEFBED = TEMP["LIEFBED"].ToString().Trim(); exAgent.SetCellValue(i + 3, 22, LIEFBED);
                    string SART = "";
                    SART = TEMP["SART"].ToString().Trim(); exAgent.SetCellValue(i + 3, 24, SART);
                    string VSPED = "";
                    VSPED = TEMP["VSPED"].ToString().Trim(); exAgent.SetCellValue(i + 3, 25, VSPED);
                    string EKPWUTERM = "";
                    EKPWUTERM = TEMP["EKPWUTERM"].ToString().Trim(); exAgent.SetCellValue(i + 3, 26, EKPWUTERM);
                    string EKPSACHB = "";
                    EKPSACHB = TEMP["EKPSACHB"].ToString().Trim(); exAgent.SetCellValue(i + 3, 27, EKPSACHB);
                    
                }
                //DataRow dwEKKOPF = tbEKKOPF.Rows[0];
                //string src = "",CURRENCY = "";

                //src = dwEKKOPF["ORDNO"].ToString();
                //exAgent.SetCellValue(4, 34, src);
                //src = dwEKKOPF["CUSTOMER"].ToString().Trim();
                //exAgent.SetCellValue(6, 5, Helper.GetGB2312Value(src));
                //src = dwEKKOPF["SUPP"].ToString().Trim();
                //exAgent.SetCellValue(6, 19, Helper.GetGB2312Value(src));
                //src = dwEKKOPF["DAT"].ToString().Trim();
                //exAgent.SetCellValue(6, 34, src);
                //src = Helper.GetGB2312Value(dwEKKOPF["INVNAME"].ToString().Trim()) + System.Environment.NewLine + Helper.GetGB2312Value(dwEKKOPF["INVADR"].ToString().Trim());
                //exAgent.SetCellValue(9, 1, src);
                //src = Helper.GetGB2312Value(dwEKKOPF["DELNAME"].ToString().Trim()) + System.Environment.NewLine + Helper.GetGB2312Value(dwEKKOPF["DELADR"].ToString().Trim());
                //exAgent.SetCellValue(9, 20, src);
                //src = dwEKKOPF["DELT"].ToString().Trim();
                //exAgent.SetCellValue(172, 7, Helper.GetGB2312Value(src));
                //src = dwEKKOPF["PAYBEZ"].ToString().Trim();
                //exAgent.SetCellValue(171, 7, Helper.GetGB2312Value(src));
                //src = dwEKKOPF["TRU"].ToString().Trim();
                //exAgent.SetCellValue(172, 25, Helper.GetGB2312Value(src));
                //src = dwEKKOPF["TOLERANCE"].ToString().Trim();
                //exAgent.SetCellValue(182, 12, Helper.GetGB2312Value(src));
                //src = dwEKKOPF["REMARK"].ToString().Trim();
                //exAgent.SetCellValue(183, 12, Helper.GetGB2312Value(src));
                //CURRENCY = dwEKKOPF["CURRENCY"].ToString().Trim();
                //exAgent.SetCellValue(13, 29, "Total value (" + Helper.GetGB2312Value(CURRENCY) + ")");

                //DataTable tbEKPOS = dsSource.Tables["EKPOS"];
                //int x = 14;
                //string wid = "", totwid = "", gm = "", sqm = "",comp ="";
                //foreach (DataRow dwEKPOS in tbEKPOS.Rows)
                //{
                //    src = dwEKPOS["POS"].ToString().Trim();
                //    exAgent.SetCellValue(x, 1, System.Convert.ToInt64(src));
                //    src = dwEKPOS["ART"].ToString().Trim() + System.Environment.NewLine + dwEKPOS["ARTDES"].ToString().Trim();
                //    exAgent.SetCellValue(x, 3, Helper.GetGB2312Value(src));
                //    src = dwEKPOS["COLOR"].ToString().Trim();
                //    exAgent.SetCellValue(x, 11, Helper.GetGB2312Value(src));
                //    src = dwEKPOS["QTY"].ToString().Trim();
                //    exAgent.SetCellValue(x, 15, System.Convert.ToDouble(src));
                //    src = dwEKPOS["UNIT"].ToString().Trim();
                //    exAgent.SetCellValue(x, 18, Helper.GetGB2312Value(src));
                //    exAgent.SetCellValue(x, 20, dwEKPOS["PRICE"].ToString().Trim() + " " + Helper.GetGB2312Value(CURRENCY).ToLower());
                //    src = dwEKPOS["SUR"].ToString().Trim();
                //    exAgent.SetCellValue(x, 23, System.Convert.ToDouble(src));
                //    src = dwEKPOS["DIS"].ToString().Trim();
                //    exAgent.SetCellValue(x, 26, System.Convert.ToDouble(src));
                //    src = dwEKPOS["SDAT"].ToString().Trim();
                //    exAgent.SetCellValue(x, 33, src);
                //    src = dwEKPOS["BDAT"].ToString().Trim();
                //    exAgent.SetCellValue(x, 37, src);
                //    src = dwEKPOS["VALUE"].ToString().Trim();
                //    exAgent.SetCellValue(x, 29, System.Convert.ToDouble(src));
                    
                //    wid = dwEKPOS["WID"].ToString().Trim();
                //    totwid = dwEKPOS["TOTWID"].ToString().Trim();
                //    gm = dwEKPOS["GM"].ToString().Trim();
                //    sqm = dwEKPOS["SQM"].ToString().Trim();
                //    comp = Helper.GetGB2312Value(dwEKPOS["COMP"].ToString().Trim());
                //    src = "Composition:" + comp; 
                //    exAgent.SetCellValue(x+1, 3, src);
                //    src = "";
                //    if (totwid != "0")
                //        {
                //            src = src + "Total width:" + totwid + "cm  ";
                //        }
                //        if (wid != "0")
                //        {
                //            src = src + "Cuttable:" + wid + "cm     ";
                //        }
                //        if (gm != "0")
                //        {
                //            src = src + "Weigth:" + gm + "g/m  " + sqm + "g/sqm ";
                //        }                    
                //    exAgent.SetCellValue(x+2, 3, src);
                //    x = x + 3;

                //}
                
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);

            }            
        }
               
    }
}
